<?php
    // print_r($_FILES);
    require_once "../../config.php";
    require_once "../../functions.php";
    //获取前端传来的数据
    $title = $_POST["title"];
    $content = $_POST["content"];
    $slug = $_POST["slug"];
    $catagory_id = $_POST["category"];
    $created = $_POST["created"];
    $status= $_POST["status"];
    // //获取文件上传的路径
    $src = $_POST["src"];
    
    //把数据插入数据库
    $connect = connect();
    //sql
    $addSql = "insert into posts (title,content,slug,feature,category_id,created,status) 
    values('{$title}','{$content}','{$slug}','{$src}','{$catagory_id}','{$created}','{$status}')";
    //执行sql语句
    $result = mysqli_query($connect,$addSql);
    //返回数据
    // print_r($resultArr);
    $response = ["code"=>0,"msg"=>"操作失败"];
    //如果查到数据
    if($result){
        $response["code"] = 1;
        $response["msg"] = "操作成功";
        $response["data"] = $result;
    }
    header("content-type:application/json;charset:utf8;");
    //以json数据返回
    echo json_encode($response);
?>